home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Macintosh / Development & Resource Tools / MacsBug6.5.3.sit / MacsBug 6.5.3 / Building dcmds / C Samples / Heap.c < prev    next >
Text File  |  1996-02-22  |  3KB  |  121 lines

  1. /*
  2.     File:        Heap.c
  3.  
  4.     Contains:    A sample dcmd which dumps heap blocks.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.  
  8.     Copyright:    © 1988, 1994, 1996 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>   25-Jan-96    JM3        Added sample build commands.
  13.          <3>   10-Dec-94    JM3        Updated for new format 3 dcmd requirements.
  14.          <2>    1-Sep-94    JM3        Included string.h so we build with no warnings with -r.
  15.  
  16.     The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
  17.     in the System folder. The dcmd's name in MacsBug will be the name of the file built by
  18.     the Linker.
  19.  
  20.     C Heap.c
  21.     Link -o Heap -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Heap.o ∂                                                                ∂
  22.         "{Libraries}Runtime.o" "{CLibraries}StdCLib.o"
  23.     BuildDcmd Heap 195 -format3
  24.     Echo 'include "Heap";'    |    Rez -a -o "{SystemFolder}Debugger Prefs"
  25.  
  26. */
  27.  
  28.  
  29. #include <Memory.h>
  30. #include <Types.h>
  31. #include <string.h>
  32.  
  33. #include "dcmd.h"
  34.  
  35.  
  36. void NumberToHex (long number, Str255 hex)
  37. {
  38.  
  39.     Str255    digits = "0123456789ABCDEF";
  40.     int        n;
  41.  
  42.     strcpy (hex, &".00000000");
  43.     hex[0] = 8;
  44.  
  45.     for (n = 8; n >= 1; n--)
  46.     {
  47.         hex[n] = digits[number % 16];
  48.         number = number / 16;
  49.     }
  50.  
  51. } // NumberToHex
  52.  
  53.  
  54. pascal void DisplayBlockInfo (long blockAddress, long blockLength, long masterPtr, short blockType, Boolean locked, Boolean purgeable, Boolean resource)
  55. {
  56.  
  57.     Str255 value;
  58.  
  59.     NumberToHex (blockAddress, value);
  60.     dcmdDrawLine (value);
  61.  
  62.     NumberToHex (blockLength, value);
  63.     dcmdDrawString ("\p ");
  64.     dcmdDrawString (value);
  65.  
  66.     if (blockType == relocatableBlock)
  67.     {
  68.         NumberToHex (masterPtr, value);
  69.         dcmdDrawString ("\p ");
  70.         dcmdDrawString (value);
  71.  
  72.         dcmdDrawString ("\p ");
  73.         if (locked)
  74.             dcmdDrawString ("\pLocked ");
  75.         if (purgeable)
  76.             dcmdDrawString ("\pPurgeable ");
  77.         if (resource)
  78.             dcmdDrawString ("\pResource ");
  79.     }
  80.  
  81. } // DisplayBlockInfo
  82.  
  83.  
  84. pascal void CommandEntry (dcmdBlock* paramPtr)
  85. {
  86.  
  87.     static const char usageStr[] = "\p";
  88.  
  89.     switch (paramPtr->request)
  90.     {
  91.         case dcmdInit:
  92.             break;
  93.  
  94.         case dcmdHelp:
  95.             dcmdDrawLine("\pDisplays information about all heap blocks.");
  96.             break;
  97.  
  98.         case dcmdGetInfo:
  99.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  100.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  101.             break;
  102.  
  103.         case dcmdDoIt:
  104.  
  105.             // Draw the column labels
  106.  
  107.             dcmdDrawLine ("\p  Address   Length  Mstr Ptr");
  108.  
  109.             // The MacsBug heap iterator will call DisplayBlockInfo once for each block in the heap.
  110.  
  111.             dcmdForAllHeapBlocks (DisplayBlockInfo);
  112.             break;
  113.  
  114.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  115.  
  116.         default:
  117.             break;
  118.     }
  119.  
  120. } // CommandEntry
  121.